﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class LoginWeb : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Session["name_user"] = "Lê Hồng Sơn";
            lblResult.Text = "";
            string type = txtMaNv.Text;
            if (type == "staff")
            {
                Response.Redirect("~/Staff_Index.aspx");
            }
            else if (type == "teacher")
            {
                Response.Redirect("~/Teacher_Mark.aspx");
            }
            else
            {
                Response.Redirect("~/Student_Info.aspx");
            }
            //string matkhau = txtMatKhau.Text;

            //string query = "SELECT StaffNumber, FirstName, LastName, Position FROM tblStaff WHERE StaffNumber = @maNv OR UserName = '120' AND Password = @matkhau";
            //ConnectDB sql = new ConnectDB();
            //sql.ClearParameter();
            //sql.AddParameter("@maNv", maNv);
            //sql.AddParameter("@matkhau", matkhau);
            //DataTable tb = sql.ExecuteSql(query);
            //if (tb != null)
            //{
            //    DataRow r = tb.Rows[0];
            //    string name = r["FirstName"].ToString() + " " + r["LastName"].ToString();
            //    Session["name_user"] = name;
            //    Session["user"] = r["StaffNumber"].ToString().Trim() ;
            //    Session["autho"] = r["Position"].ToString().Trim();
            //    lblResult.Text = "";
            //    Response.Redirect("~/Index.aspx");
            //}
            //else
            //{
            //    lblResult.Text = "Mã nhân viên hoặc mật khẩu không đúng";
            //}
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        txtMaNv.Text = "";
        txtMatKhau.Text = "";
    }
}